<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	template="/WEB-INF/layouts/standard.xhtml" 
	xmlns:a4j="http://richfaces.org/a4j" 
	xmlns:rich="http://richfaces.org/rich"
	xmlns:bf="http://www.bssmanager.com/jsf" 
	xmlns:c="http://java.sun.com/jstl/core">

	<ui:define name="formheader">
		<h2>Buildings</h2>
	</ui:define>
	
	<ui:define name="formGlobal">
		<bf:dateSelector controller="#{buildingController}" date="date" ajaxUpdate="false"/>
	</ui:define>

	<ui:define name="content">

		<c:set var="controller" value="${buildingController}"/>
		<h:messages errorClass="errors" style="color:#ff1111"/>

		<h:form id="#{controller.modelName}">

			<h:panelGrid columns="1" width="100%">
				<rich:panel style="border:0">
									<f:facet name="header">
										<h:outputText value="Add New Building"/>
									</f:facet>	
					<h:panelGrid columns="2" >
						<h:outputLabel value="Name:" />
						<h:outputText rendered="#{controller.editing}" value="#{controller.model.name}" />
						<h:inputText rendered="#{not controller.editing}" value="#{controller.model.name}" />
						<h:outputLabel value="Floors:" />
						<h:inputText id="floors" value="#{controller.model.floors}"/>	
					</h:panelGrid>
					<h:panelGroup>
						<h:commandButton rendered="#{not controller.editing}" id="submit" action="#{controller.add}" value="Add" />
						<rich:spacer width="10px"/>
						<h:commandButton rendered="#{controller.editing}" action="#{controller.update}" value="Update" />
						<rich:spacer width="10px"/>
						<h:commandButton id="cancel" value="Cancel" action="#{controller.cancel}" />
					</h:panelGroup>
				</rich:panel>									
			
				<rich:panel style="border:0">
					<f:facet name="header">
						<h:outputText value="All Buildings"/>
					</f:facet>	
					<rich:dataTable value="${controller.data}" var="aBean" align="left">						
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Edit" />
							</f:facet>
							<h:commandButton style="width:15px;height:15px;#{controller.editing ? 'cursor: not-allowed':''}"
								title="#{controller.editing ? 'Edit already in progress...':'Click to Edit'}" image="/resrc/images/edit1.jpg"
								disabled="#{controller.editing}" action="${controller.select}" />
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Delete" />
							</f:facet>
							<h:commandButton
								title="#{controller.editing ? 'Edit is in progress, please complete the editing...':'Click to Delete'}"
								image="/resrc/images/cross1.jpg" style="width:15px;height:15px;#{controller.editing ? 'cursor: not-allowed':''}"
								disabled="#{controller.editing}" action="${controller.remove}" immediate="true"
								onclick="if(!showConfirmation('Are you sure to remove #{controller.modelName}: #{aBean.name} ?')) return false;" />
						</rich:column>
						<rich:column>
							<f:facet name="header">Name</f:facet>
							<h:outputText value="#{aBean.name}" />
						</rich:column>
						<rich:column>
							<f:facet name="header">Floors</f:facet>
							<h:outputText value="#{aBean.floors}" />
						</rich:column>
						<f:facet name="footer">
							<h:outputText rendered="#{controller.data.rowCount le 0}" value="No #{controller.modelName}s available..." />
						</f:facet>
					</rich:dataTable>
				</rich:panel>						
			</h:panelGrid>			
		</h:form>
	</ui:define>
</ui:composition>